#include "head.h"

/* Usage:  */
bool my_cd(sendMsg msg, client_status *clients, int net_fd) {
    // 函数是否要用指针
    memset(msg.msg, 0, sizeof(msg.msg));
    msg.mode = 1;
    // 检查路径是否以斜杠结尾

    strcpy(msg.msg, clients->path_last);
    send(net_fd, &msg, sizeof(msg), MSG_NOSIGNAL);

    recvMsg ret_msg;
    recv(net_fd, &ret_msg, sizeof(ret_msg), 0);


    if (strcmp(ret_msg.statu, "true") == 0) {
        // 更改用户端当前 cur_path 为发送过来的信息
        strncpy(clients->path, ret_msg.msg, sizeof(clients->path) - 1);
        clients->path[sizeof(clients->path) - 1] = '\0'; // 确保路径以 null 结尾
    }
    if (strcmp(ret_msg.statu, "error") == 0) {
        // 打印错误
        printf("Error: Failed to change directory.\n");
    }
    return 0;
}
